var events = require('events'),
  eventEmitter = new events.EventEmitter();

var connectedHandler = function connected() {
  console.log('连接成功！');
  eventEmitter.emit('data_received');
};
eventEmitter.on('connection', connectedHandler);
eventEmitter.on('data_received', function() {
  console.log('接受到消息！');
});

// 触发 connection 事件
eventEmitter.emit('connection');

console.log("程序执行完毕。");
